#include <stdlib.h>
#include <SDL.h>
#include <SDL_image.h>
#include "graphics.h"



struct Image
{
	SDL_Surface * image;
};


static SDL_Surface * screen;


int init_graphics(int width, int height, int bpp)
{
	SDL_Init(SDL_INIT_VIDEO);
	screen = SDL_SetVideoMode(width, height ,bpp, 0);
	return 0;
}

HImage load_png(const char * path)
{
	HImage img = (struct Image*)malloc(sizeof(struct Image));
	img->image = IMG_Load(path);
	return img;
}

int free_image(HImage image)
{
	SDL_FreeSurface(image->image);
	free(image);
	return 0;
}

void enable_blend(int blend){};

void add_image(HImage image, int x, int y, int w, int h, int clipX, int clipY, int clipW, int clipH)
{
	SDL_Rect src = {clipX, clipY, clipW, clipH};
	SDL_Rect dst = {x, y, w, h};
	SDL_BlitSurface(image->image, &src, screen, &dst);
}

void render_scene(void)
{
	SDL_Flip(screen);
}